package cn.lanqiao.bigDate.web.controller;

import cn.lanqiao.bigDate.entity.data.DataComment;
import cn.lanqiao.bigDate.reslut.Result;
import cn.lanqiao.bigDate.web.BaseController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping(DataCommController.BASE_URL)
public class DataCommController extends BaseController {
    public static final String BASE_URL = "dataComment";
    /**
     * 页面跳转
     * @return
     */
    @RequestMapping(value = "toIndex")
    public ModelAndView toIndex() {
        ModelAndView mav = new ModelAndView();
        mav.setViewName(BASE_URL + "/index"); //指定路径
        return mav;
    }
    /**
     * 分页查询
     * @return
     */
    @GetMapping(value = "findByPage")
    public IPage<DataComment> findByPage(Page<DataComment> page, String searchDeptName) {
        return dataCommentService.findByPage(page,searchDeptName);
    }
    /**
     * 单个查询
     * @return
     */
    @GetMapping(value = "findDataCommOne")
    public DataComment findDataCommOne(Long id) {
        return dataCommentService.findDataCommOne(id);
    }

    /**
     * 修改
     * @param dataComment
     * @return
     */
    @PostMapping(value = "updateDataComm")
    public Result<String> updateDataComm(DataComment dataComment) {
        Result<String> reslut = new Result();
        Boolean isSuccess = dataCommentService.updateDataComment(dataComment);
        if(isSuccess){
            reslut.setCode(200);
            reslut.setMsg("修改成功");
        }else{
            reslut.setCode(500);
            reslut.setMsg("修改失败");
        }
        return reslut;
    }
    /**
     * 添加
     * @param dataComment
     * @return
     */
    @RequestMapping(value = "saveDataComm")
    public Result<String> saveDataComm(DataComment dataComment) {
        System.out.println(dataComment);
        Result<String> reslut = new Result();
        Boolean isSuccess = dataCommentService.saveDataComment(dataComment);
        if(isSuccess){
            reslut.setCode(200);
            reslut.setMsg("添加成功");
        }else{
            reslut.setCode(500);
            reslut.setMsg("添加失败");
        }
        return reslut;
    }

    /**
     * 按id删除
     * @param ids
     * @return
     */

    @RequestMapping(value = "deleteDataComm")
    public Result<String> deleteDataComm(String ids) {
        String s = String.valueOf(ids);
        Result<String> reslut = new Result();
        Boolean isSuccess = dataCommentService.deleteDataComment(s);
        if(isSuccess){
            reslut.setCode(200);
            reslut.setMsg("删除成功");
        }else{
            reslut.setCode(500);
            reslut.setMsg("删除失败");
        }
        return reslut;
    }
}
